<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Redis 崩溃优化与恢复指南</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
        }
        .code-block {
            background: #1e1e1e;
            color: #d4d4d4;
            border-radius: 8px;
            padding: 1.5rem;
            overflow-x: auto;
            font-family: 'Consolas', 'Monaco', monospace;
        }
        .section-title {
            position: relative;
            padding-left: 1rem;
        }
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 100%;
            background: linear-gradient(180deg, #667eea 0%, #764ba2 100%);
        }
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
        .feature-icon {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        .animate-fadeInUp {
            animation: fadeInUp 0.6s ease-out;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white py-20 px-6">
        <div class="max-w-6xl mx-auto text-center animate-fadeInUp">
            <h1 class="text-5xl md:text-6xl font-bold mb-6">
                <i class="fas fa-database mr-4"></i>Redis 崩溃优化与恢复
            </h1>
            <p class="text-xl md:text-2xl mb-8 opacity-90">
                高性能缓存系统的稳定性保障策略
            </p>
            <div class="bg-white bg-opacity-20 backdrop-blur-md rounded-lg p-6 max-w-3xl mx-auto">
                <p class="text-lg leading-relaxed">
                    在现代应用中，Redis 是一个关键的高性能缓存和数据存储解决方案。当 Redis 服务器出现崩溃时，可能会影响应用的性能和可用性，因此需要迅速有效地进行优化和恢复。
                </p>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="max-w-7xl mx-auto px-6 py-12">
        
        <!-- Architecture Overview -->
        <div class="bg-white rounded-2xl shadow-xl p-8 mb-12 card-hover">
            <h2 class="text-3xl font-bold mb-6 text-gray-800">
                <i class="fas fa-sitemap mr-3 feature-icon"></i>Redis 优化架构全景
            </h2>
            <div class="mermaid">
                graph TB
                    A[Redis 崩溃优化] --> B[数据持久化]
                    A --> C[系统资源管理]
                    A --> D[高可用性方案]
                    A --> E[监控预警]
                    A --> F[安全防护]
                    
                    B --> B1[RDB 快照]
                    B --> B2[AOF 日志]
                    
                    C --> C1[内存管理]
                    C --> C2[磁盘 I/O]
                    
                    D --> D1[主从复制]
                    D --> D2[Redis Sentinel]
                    D --> D3[集群模式]
                    
                    E --> E1[实时监控]
                    E --> E2[自动预警]
                    
                    F --> F1[访问控制]
                    F --> F2[网络安全]
                    
                    style A fill:#667eea,stroke:#fff,stroke-width:3px,color:#fff
                    style B fill:#f59e0b,stroke:#fff,stroke-width:2px,color:#fff
                    style C fill:#10b981,stroke:#fff,stroke-width:2px,color:#fff
                    style D fill:#3b82f6,stroke:#fff,stroke-width:2px,color:#fff
                    style E fill:#8b5cf6,stroke:#fff,stroke-width:2px,color:#fff
                    style F fill:#ef4444,stroke:#fff,stroke-width:2px,color:#fff
            </div>
        </div>

        <!-- Section 1: 数据持久化配置 -->
        <div class="bg-white rounded-2xl shadow-xl p-8 mb-12 card-hover">
            <h2 class="text-3xl font-bold mb-8 text-gray-800 section-title">
                <i class="fas fa-save mr-3 text-yellow-500"></i>1. 数据持久化配置
            </h2>
            
            <div class="grid md:grid-cols-2 gap-8">
                <!-- RDB 快照 -->
                <div class="bg-gradient-to-br from-yellow-50 to-orange-50 rounded-xl p-6">
                    <h3 class="text-xl font-semibold mb-4 text-gray-800">
                        <i class="fas fa-camera mr-2 text-yellow-600"></i>RDB 快照
                    </h3>
                    <p class="text-gray-700 mb-4">
                        检查并调整 RDB 快照的配置，以减少 Redis 崩溃时的数据丢失。适当缩短 save 参数的时间间隔，但要考虑系统性能。
                    </p>
                    <div class="code-block">
                        <pre># 每 60 秒内至少 1000 个键被修改
save 60 1000</pre>
                    </div>
                    <div class="mt-4 p-4 bg-white rounded-lg">
                        <p class="text-sm text-gray-600">
                            <i class="fas fa-lightbulb mr-2 text-yellow-500"></i>
                            定期备份 Redis 数据文件，并将备份存储在安全的位置。
                        </p>
                    </div>
                </div>

                <!-- AOF -->
                <div class="bg-gradient-to-br from-blue-50 to-indigo-50 rounded-xl p-6">
                    <h3 class="text-xl font-semibold mb-4 text-gray-800">
                        <i class="fas fa-file-alt mr-2 text-blue-600"></i>AOF 日志
                    </h3>
                    <p class="text-gray-700 mb-4">
                        使用 AOF 日志记录每个写操作，减少数据丢失。配置适当的同步策略。
                    </p>
                    <div class="code-block mb-4">
                        <pre>appendonly yes
appendfsync everysec</pre>
                    </div>
                    <div class="code-block">
                        <pre>auto-aof-rewrite-min-size 64mb
auto-aof-rewrite-percentage 100</pre>
                    </div>
                </div>
            </div>
        </div>

        <!-- Section 2: 系统资源管理 -->
        <div class="bg-white rounded-2xl shadow-xl p-8 mb-12 card-hover">
            <h2 class="text-3xl font-bold mb-8 text-gray-800 section-title">
                <i class="fas fa-server mr-3 text-green-500"></i>2. 系统资源管理
            </h2>
            
            <div class="grid md:grid-cols-2 gap-8">
                <!-- 内存管理 -->
                <div class="bg-gradient-to-br from-green-50 to-emerald-50 rounded-xl p-6">
                    <h3 class="text-xl font-semibold mb-4 text-gray-800">
                        <i class="fas fa-memory mr-2 text-green-600"></i>内存管理
                    </h3>
                    <p class="text-gray-700 mb-4">
                        监控 Redis 服务器的内存使用情况，设置合理的限制和策略。
                    </p>
                    <div class="code-block">
                        <pre>maxmemory 2gb
maxmemory-policy allkeys-lru</pre>
                    </div>
                    <div class="mt-4 flex items-center space-x-4">
                        <div class="flex-1 bg-white rounded-lg p-4 text-center">
                            <i class="fas fa-chart-line text-3xl text-green-500 mb-2"></i>
                            <p class="text-sm text-gray-600">实时监控</p>
                        </div>
                        <div class="flex-1 bg-white rounded-lg p-4 text-center">
                            <i class="fas fa-cog text-3xl text-green-500 mb-2"></i>
                            <p class="text-sm text-gray-600">优化配置</p>
                        </div>
                    </div>
                </div>

                <!-- 磁盘 I/O -->
                <div class="bg-gradient-to-br from-purple-50 to-pink-50 rounded-xl p-6">
                    <h3 class="text-xl font-semibold mb-4 text-gray-800">
                        <i class="fas fa-hdd mr-2 text-purple-600"></i>磁盘 I/O
                    </h3>
                    <ul class="space-y-3">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-purple-500 mt-1 mr-3"></i>
                            <div>
                                <p class="font-semibold text-gray-800">优化磁盘 I/O</p>
                                <p class="text-gray-600 text-sm">使用 SSD 替代传统 HDD，确保磁盘空间充足</p>
                            </div>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-purple-500 mt-1 mr-3"></i>
                            <div>
                                <p class="font-semibold text-gray-800">监控磁盘健康</p>
                                <p class="text-gray-600 text-sm">定期检查磁盘状态，预防潜在故障</p>
                            </div>
                        </li>
                    </ul>
                </div>
            </div>
        </div>

        <!-- Section 3: 高可用性和灾备方案 -->
        <div class="bg-white rounded-2xl shadow-xl p-8 mb-12 card-hover">
            <h2 class="text-3xl font-bold mb-8 text-gray-800 section-title">
                <i class="fas fa-shield-alt mr-3 text-blue-500"></i>3. 高可用性和灾备方案
            </h2>
            
            <div class="grid md:grid-cols-3 gap-6">
                <!-- 主从复制 -->
                <div class="bg-gradient-to-br from-blue-50 to-cyan-50 rounded-xl p-6">
                    <div class="text-center mb-4">
                        <i class="fas fa-sync-alt text-4xl text-blue-600"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-3 text-center text-gray-800">主从复制</h3>
                    <p class="text-gray-700 mb-4 text-sm">
                        确保数据在多个节点上有备份，提高系统可靠性。
                    </p>
                    <div class="code-block text-sm">
                        <pre>replicaof &lt;master-ip&gt; &lt;master-port&gt;</pre>
                    </div>
                </div>

                <!-- Redis Sentinel -->
                <div class="bg-gradient-to-br from-indigo-50 to-purple-50 rounded-xl p-6">
                    <div class="text-center mb-4">
                        <i class="fas fa-eye text-4xl text-indigo-600"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-3 text-center text-gray-800">Redis Sentinel</h3>
                    <p class="text-gray-700 mb-4 text-sm">
                        自动监控和故障转移，确保服务持续可用。
                    </p>
                    <div class="code-block text-sm">
                        <pre>sentinel monitor mymaster &lt;ip&gt; &lt;port&gt; 2</pre>
                    </div>
                </div>

                <!-- 集群模式 -->
                <div class="bg-gradient-to-br from-pink-50 to-red-50 rounded-xl p-6">
                    <div class="text-center mb-4">
                        <i class="fas fa-network-wired text-4xl text-pink-600"></i>
                    </div>